#!/usr/bin/python
# -*- coding: utf-8 -*-

#-------------------------------------------------
#Create At: 2008-6-21 上午06:37:46 
#Create By: Fla.sam
#
#DESC: google app blog models
#
#-------------------------------------------------

from appengine_django.models import BaseModel
from google.appengine.ext import db
import random

class Tag( BaseModel ):
    tag_name = db.StringProperty( required=True )
    tag_rating = db.IntegerProperty()
    
    @property
    def articles( self ):
        return Article.gql( 'WHERE article_tags = :tag', tag=self.key() )
    
    @property
    def random_rating( self ):
        '''
        @param mode:random, or by rating value
        '''
        _s = range( 1, 5 )
        return random.choice( _s )
#    
#    @property
#    def rating(self):
#        return self.tag_rating
    
class Link( BaseModel ):
    link_name = db.StringProperty( required=True )
    link_url = db.LinkProperty( required=True )
    link_tag = db.ReferenceProperty( Tag )
    
class Article( BaseModel ):
    article_title = db.StringProperty( required=True )
    article_content = db.TextProperty( required=True )
    article_datetime = db.DateTimeProperty( auto_now_add=True )
    article_rating = db.RatingProperty()
    article_hit = db.IntegerProperty()
    article_tags = db.ListProperty( db.Key )
    article_publiced = db.BooleanProperty( required=True )
    article_submit_user = db.UserProperty( required=True )
    
#    @property
#    def public_form(self):
#        if self.article_publiced:
#            return ''
    
class Comment( BaseModel ):
    comment_article = db.ReferenceProperty( Article )
    comment_datetime = db.DateTimeProperty( auto_now_add=True ) 
    comment_content = db.StringProperty()

class SiteOptions( BaseModel ):
    site_closed = db.BooleanProperty( default=False )
    site_closed_msg = db.StringProperty( default='' )
    site_rss_closed = db.BooleanProperty( default=False )
    site_private = db.BooleanProperty( default=False )
    site_allow_user_post_article = db.BooleanProperty( default=False )
    site_allow_user_comment = db.BooleanProperty( default=False )
    site_allow_user_ratio_article = db.BooleanProperty( default=True )   
    site_front_show_article_summary = db.BooleanProperty( default=False )
